/*************************************************
Author: will
Date: 1/8/2013
Description:
Notes: 
*************************************************/

#ifndef __CLevelItemConfig_h__
#define __CLevelItemConfig_h__

#include "CTArray.h"
#include "commclass.h"
#include "commerrno.h"
#include "CDropItemSubType.h"
#include "../common/CRandom.h"

typedef CRandomSet<MAX_ITEM_TYPE_DROP_COUNT> T_ITEM_TYPE_DROP;
class CLevelItemConfigData
{
public:
    CLevelItemConfigData() 
        :_bHasConfig(false)
    {
    }

    virtual ~CLevelItemConfigData() 
    {
    }

    void Clear ()
    {
        _bHasConfig = false;
        _usLevel = 0;
        _iExpPara = 0;
        _iSilverPara = 0;
        _iEnemyAtkCityBonusPara = 0;
        _stDropSet1.Clear();
        _stDropSet2.Clear();
        _stDropSet3.Clear();
        _stDropSet4.Clear();
    }

public:
    bool _bHasConfig;

    unsigned short _usLevel;

    int   _iExpPara;        //金币常量
    int   _iSilverPara;     //银币常量
    int   _iEnemyAtkCityBonusPara;  //怪物攻城战奖励系数
    T_ITEM_TYPE_DROP _stDropSet1;
    T_ITEM_TYPE_DROP _stDropSet2;
    T_ITEM_TYPE_DROP _stDropSet3;
    T_ITEM_TYPE_DROP _stDropSet4;
};

class CLevelItemConfig
{
public:
    CLevelItemConfig() 
    {
        _astLevelItemConfigDatas.m_iUsedCount = _astLevelItemConfigDatas.GetCount();
    }

    virtual ~CLevelItemConfig() 
    {
    }

    int AddConfig(CLevelItemConfigData& stConfigData)
    {
        if (stConfigData._usLevel <= 0 || stConfigData._usLevel >= _astLevelItemConfigDatas.GetCount())
        {
            CT_ERROR(("%d", stConfigData._usLevel));
            return RET_SYS_ERROR;
        }

        if (stConfigData._usLevel != 1 && !_astLevelItemConfigDatas[stConfigData._usLevel - 1]._bHasConfig)
        {
            CT_ERROR(("%d", stConfigData._usLevel));
            return RET_SYS_ERROR;
        }

        if (_astLevelItemConfigDatas[stConfigData._usLevel]._bHasConfig)
        {
            CT_ERROR(("%d", stConfigData._usLevel));
            return RET_SYS_ERROR;
        }

        _astLevelItemConfigDatas[stConfigData._usLevel] = stConfigData;
        _astLevelItemConfigDatas[stConfigData._usLevel]._bHasConfig = true;

        return 0;
    }

    int GetConfig(unsigned short usLevel, CLevelItemConfigData& stConfigData)
    {
        if (usLevel <= 0 || usLevel >= _astLevelItemConfigDatas.Size())
        {
            CT_ERROR(("%d", usLevel));
            return RET_SYS_ERROR;
        }

        if (!_astLevelItemConfigDatas[usLevel]._bHasConfig)
        {
            CT_ERROR(("%d", usLevel));
            return RET_SYS_ERROR;
        }

        stConfigData = _astLevelItemConfigDatas[usLevel];

        return 0;
    }

public:
    CTLib::CTArray<CLevelItemConfigData, MAX_ROLE_LEVEL + 1> _astLevelItemConfigDatas;
};


#endif // __CLevelItemConfig_h__

